<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,viewport-fit=cover,maximum-scale=1.0,minimum-scale=1.0,user-scalable=no">
    <title>尤迈桃李会</title>
    <script src="js/rem.js"></script>
    <link rel="stylesheet" href="css/weui.min.css">
    <link rel="stylesheet" href="css/jquery-weui.min.css">
    <link rel="stylesheet" href="css/public.css">
    <link rel="stylesheet" href="css/user.css">
    <script>(function() {var _53code = document.createElement("script");_53code.src = "https://tb.53kf.com/code/code/96d8f960b261e49515450f8953b044bc5/1";var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(_53code, s);})();</script>
</head>
<body>
    <div class="user-auth bgwhite" id="main">
        <div class="top-space"></div>
        <div class="plr15">
            <p class="pub-user-tit">医学生认证</p>
        </div>
        <form action="#" id="saveStudent" autocomplete="off">
            <div class="pub-box space-border plr15">
                <span class="pub-desc"><i class="i-required">*</i>姓名</span>
                <input class="pub-text" type="text" name="userName">
            </div>
            <div class="pub-box space-border plr15">
                <span class="pub-desc"><i class="i-required">*</i>手机号</span>
                <input class="pub-text" type="text" id="loginMobileView" value="">
                <input class="pub-text" type="hidden" name="loginMobile" value="">
            </div>
            <div class="pub-box space-border plr15" id="selectSchool">
                <span class="pub-desc"><i class="i-required">*</i>学校</span>
                <div>
                    <span id="schoolView"></span>
                    <span class="right-arrow-btn"></span>
                </div>
                <input type="hidden" name="school" value="">
                <input type="hidden" name="schoolCode" value="">
                <input type="hidden" name="provinceCode" value="">
                <input type="hidden" name="cityCode" value="">
            </div>
            <div class="pub-box space-border plr15" id="selectSpecial">
                <span class="pub-desc"><i class="i-required">*</i>专业</span>
                <div>
                    <span id="specialView"></span>
                    <span class="right-arrow-btn"></span>
                </div>
                <input type="hidden" name="special" value="">
                <input type="hidden" name="specialCode" value="">
            </div>
            <div class="pub-box space-border plr15">
                <span class="pub-desc"><i class="i-required">*</i>学历</span>
                <div>
                    <span id="educationView"></span>
                    <span class="right-arrow-btn"></span>
                </div>
                <input class="pub-picker-input" type="text" name="education" value="">
            </div>
            <div class="pub-box space-border plr15">
                <span class="pub-desc"><i class="i-required">*</i>入学年份</span>
                <div>
                    <span id="enterYearView"></span>
                    <span class="right-arrow-btn"></span>
                </div>
                <input class="pub-picker-input" type="text" name="enterYear" value="">
            </div>
            <div class="pub-box space-border plr15" id="selectStudent">
                <span class="pub-desc"><i class="i-required">*</i>学生证/毕业证</span>
                <span class="right-arrow-btn"></span>
                <input type="hidden" name="cardId" value="">
                <input type="hidden" name="studentId" value="">
                <input type="hidden" name="studyId" value="">
            </div>
            <div class="submit-box">
                <input class="pub-submit-btn" type="submit" value="提交申请">
                <div class="btn-wrapper">
                    <a class="choose-identity" href="javascript:history.back(-1)">选择其他身份</a>
                </div>
            </div>
        </form>
    </div>
    <script src="js/jquery-3.6.0.min.js"></script>
    <script src="js/jquery-weui.min.js"></script>
    <script src="js/md5.js"></script>
    <script src="js/public.js"></script>
    <script>
        // 获取手机号
        var phone = localStorage.getItem('mobile');
        $('[name=loginMobile]').val(phone);
        $('#loginMobileView').val(phoneDesensitization(phone));

        // 监听手机号输入
        $('#loginMobileView').on('input', function(){
            $('[name=loginMobile]').val($(this).val());
        })

        // 选择学校
        $('#selectSchool').click(function(){
            $('#main').hide();
            $('#schoolMoudle').show();
        })

        // 选择专业
        $('#selectSpecial').click(function(){
            if(!$('[name=schoolCode]').val()){
                toast('请先选择学校');
                return;
            }
            $('#main').hide();
            $('#specialMoudle').show();
        })

        // 选择学历
        $('[name=education]').picker({
            title: "请选择您的学历",
            cols: [{
                textAlign: 'center',
                displayValues: ['大专以下', '大专', '本科', '研究生', '硕士', '博士', '博士后'],
                values: [1, 2, 3, 4, 5, 6, 7]
            }],
            onChange: function(e){
                $('#educationView').html(e.cols[0].displayValue);
            }
        });

        // 选择入学年份
        function getYearList(){
            var nowYear = new Date().getFullYear();
            var yearList = []
            for(var i = 0; i < 50; i++){
                yearList.push(nowYear - i);
            }

            return yearList;
        }
        $('[name=enterYear]').picker({
            title: "请选择您的入学年份",
            cols: [{
                textAlign: 'center',
                values: getYearList()
            }],
            onChange: function(e){
                $('#enterYearView').html(e.cols[0].value);
            }
        });

        // 选择专业
        $('#selectStudent').click(function(){
            $('#main').hide();
            $('#studentModule').show();
        })

        // 提交申请
        // 数据验证
        function dataValidation(doctor){
            var msg = {
                userName: '姓名不能为空',
                schoolCode: '请选择学校',
                specialCode: '请选择专业',
                enterYear: '请选择入学年份',
                education: '请选择学历',
                cardId: '请选择证件',
                loginMobile: '请填写用户手机号'
            };
            for(var k in msg){
                if(validEmpty(doctor[k], msg[k])) return true;
            }

            if(validPhone(doctor.loginMobile, '手机号格式不正确')) return true;
            return false;
        }
        // 提交
        var subState = false; // 防重
        $('#saveStudent').submit(function(){
            if(subState) return false;
            var option = $(this).serializeObject();
            if(dataValidation(option)) return false;
            var url = getQueryString('type') === 'reAuth' ? '/userMessage/saveStudent' : '/userMessage/updateStudent';
            subState = true
            // 医学生认证信息保存
            http(url, {
                hasToken: true,
                data: option,
                success: function(res){
                    if(res.code === '01'){
                        // toast('提交成功');
                        toast('资料提交成功，请等待审核');
                        backIndex(1000);
                    }
                },
                complete: function(){
                    subState = false;
                }
            })
            return false;
        })
    </script>

    <!-- 选择学校 -->
    <div class="user-choose bgwhite" id="schoolMoudle" style="display: none;">
        <div class="search-box">
            <input class="search" type="text" placeholder="输入学校名称" id="searchSchool">
        </div>
        <ul class="main">
            <li class="area-item department" id="provinceList">
            </li>
            <li class="area-item city" id="schoolList">
            </li>
        </ul>
        <div class="footer submit-box">
            <input class="pub-submit-btn" id="schoolConfirm" type="button" value="确定">
        </div>
    </div>
    <script>
        // 查询学校
        $('#searchSchool').keypress(function(e){
            if(e.keyCode != 13) return;
            updateSchool(true);
        })
        // 获取省市区数据
        http('/hospital/getAllList', {
            noEncry: true,
            success: function(res){
                if(res.code === '01'){
                    // 更新省
                    var provinceData = res.data;
                    $('#provinceList').html(getListHtml(provinceData, 'areaCode', 'areaName'));

                    // 更新学校
                    updateSchool();
                }
            }
        })
        // 更新学校
        function updateSchool(type){
            http('/school/getAllList', {
                data: {
                    provinceCode: $('#provinceList p.active').attr('data-code'),
                    schoolName: $.trim($('#searchSchool').val())
                },
                success: function(res){
                    if(res.code === '01'){
                        var schoolList = res.data;
                        // 更新学校
                        var schoolHtml = getListHtml(schoolList, 'id', 'name');
                        $('#schoolList').html(schoolHtml);
                    }
                }
            })
        }

        // 省份选择
        $('#provinceList').click(function(e){
            changeSelected($(e.target));
            // 更新学校
            updateSchool();
        });
        $('#schoolList').click(function(e){
            changeSelected($(e.target));
        });

        // 确定点击事件
        $('#schoolConfirm').click(function(e){
            var provinceCode = $('#provinceList').find('p.active').attr('data-code');
            var $schoolEle = $('#schoolList').find('p.active');
            var school = $schoolEle.text();
            var schoolCode = $schoolEle.attr('data-code');
            $('[name=provinceCode]').val(provinceCode);
            $('[name=school]').val(school);
            $('[name=schoolCode]').val(schoolCode);

            $('#schoolView').text(school);
            $('#main').show();
            $('#schoolMoudle').hide();

            // 清空已选专业
            $('[name=special]').val('');
            $('[name=specialCode]').val('');
            $('#specialView').text('');
            getSpecialList();
        })
    </script>

    <!-- 选择专业 -->
    <div class="user-choose bgwhite" id="specialMoudle" style="display: none;">
        <div class="search-box">
            <input class="search" type="text" placeholder="输入专业名称" id="searchSpecial">
        </div>
        <ul class="main">
            <li class="area-item plr15" id="specialList">
            </li>
        </ul>
        <div class="footer"></div>
    </div>
    <script>
        // 获取专业数据
        function getSpecialList(){
            http('/special/getAllList', {
                noEncry: true,
                data: {
                    specialName: $.trim($('#searchSpecial').val()),
                    schoolCode: $('[name=schoolCode]').val()
                },
                success: function(res){
                    if(res.code === '01'){
                        // 更新专业列表
                        var specialData = res.data;
                        var html = '';
                        specialData.forEach(special => {
                            html += '<div class="pub-box" data-code="' + special.id + '">' + 
                                '<span class="pub-desc">' + special.name + '</span>' + 
                                '<span class="right-arrow-btn"></span>' + 
                            '</div>';
                        });
                        var txt = specialData.length === 0 ? '暂无数据，点击返回' : '没有更多数据了';
                        html += getNoDataHtml(txt);
                        $('#specialList').html(html);
                    }
                }
            })
        }

        // 选择专业
        $('#specialList').click(function(e){
            var $target = $(e.target);
            if(e.target == this) return;
            if(!$target.hasClass('pub-box')){
                $target = $target.parent('.pub-box');
            }
            var special = $target.find('.pub-desc').text();

            $('[name=special]').val(special);
            $('[name=specialCode]').val($target.attr('data-code'));

            $('#specialView').text(special);
            $('#main').show();
            $('#specialMoudle').hide();
            $('#searchSpecial').val('');
        })

        // 查询专业
        $('#searchSpecial').keypress(function(e){
            if(e.keyCode != 13) return;
            getSpecialList();
        })
    </script>

    <!-- 选择专业 -->
    <!-- <div class="user-choose bgwhite" id="specialMoudle" style="display: none;">
        <div class="search-box">
            <input class="search" type="text" placeholder="输入专业名称" id="searchSpecial">
        </div>
        <ul class="main">
            <li class="area-item" id="specialList">
            </li>
        </ul>
        <div class="footer submit-box">
            <input class="pub-submit-btn" id="specialConfirm" type="button" value="确定">
        </div>
    </div>
    <script>
        // 查询专业
        $('#searchSpecial').keypress(function(e){
            if(e.keyCode != 13) return;
            getSpecialList();
        })
        // 获取专业数据
        function getSpecialList(){
            http('/special/getAllList', {
                noEncry: true,
                data: {
                    specialName: $.trim($('#searchSpecial').val()),
                    schoolCode: $('[name=schoolCode]').val()
                },
                success: function(res){
                    if(res.code === '01'){
                        // 更新专业列表
                        var specialData = res.data;
                        $('#specialList').html(getListHtml(specialData, 'id', 'name'));
                    }
                }
            })
        }

        $('#specialList').click(function(e){
            changeSelected($(e.target));
        });

        // 确定点击事件
        $('#specialConfirm').click(function(e){
            var $specialEle = $('#specialList').find('p.active');
            var special = $specialEle.text();
            var specialCode = $specialEle.attr('data-code');
            $('[name=special]').val(special);
            $('[name=specialCode]').val(specialCode);

            $('#specialView').text(special);
            $('#main').show();
            $('#specialMoudle').hide();
        })
    </script> -->

    <!-- 学生证/毕业证 -->
    <div class="user-auth-certificate bgwhite" id="studentModule" style="display: none;">
        <div class="top-space"></div>
        <div class="plr15">
            <p class="pub-user-tit">医学生认证</p>
        </div>
        <form method="post" onsubmit="submitCard();return false;" action="#">
            <div class="upload-box">
                <div class="upload-inner-box">
                    <i class="i-required">*</i>
                    <div class="input-box">
                        <image class="upload-img hide" src=""></image>
                        <span class="upload-step">第一步</span>
                        <div class="upload-center">
                            <i class="upload-icon"></i>
                            <p class="upload-txt">上传身份证人像面</p>
                        </div>
                        <input class="unload-input" data-type="cardId" type="file" name="cardFile" value="" accept="image/*">
                    </div>
                </div>
                <div class="upload-inner-box">
                    <i class="i-required">*</i>
                    <div class="input-box">
                        <image class="upload-img hide" src=""></image>
                        <span class="upload-step">第二步</span>
                        <div class="upload-center">
                            <i class="upload-icon"></i>
                            <p class="upload-txt">上传毕业证</p>
                        </div>
                        <input class="unload-input" data-type="studentId" type="file" name="doctorFile" value="" accept="image/*">
                    </div>
                </div>
                <div class="upload-inner-box">
                    <i class="i-required">*</i>
                    <div class="input-box">
                        <image class="upload-img hide" src=""></image>
                        <span class="upload-step">第三步</span>
                        <div class="upload-center">
                            <i class="upload-icon"></i>
                            <p class="upload-txt">上传学生证</p>
                        </div>
                        <input class="unload-input" data-type="studyId" type="file" name="pratitionFile" value="" accept="image/*">
                    </div>
                </div>
            </div>
            <div class="upload-example plr15">
                <h4 class="example-tit">图片示例</h4>
                <ul class="examples flex-btw">
                    <li>标准</li>
                    <li>信息缺失</li>
                    <li>模糊</li>
                    <li>闪光强烈</li>
                </ul>
            </div>
            <div class="submit-box">
                <p class="tip">*认证信息仅用于审核，我们将严格保护你的隐私</p>
                <input class="pub-submit-btn" type="submit" value="提交认证">
                <div class="btn-wrapper">
                    <a class="choose-identity" href="javascript:history.back(-1)">选择其他身份</a>
                </div>
            </div>
        </form>
    </div>
    <script>
        var imgList = {
            cardId: '',
            studentId: '',
            studyId: ''
        }
        $('.unload-input').change(function(e){
            fileUpload(this);
        })

        function fileUpload(fileInput, type){
            var type = $(fileInput).attr('data-type');
            var file = fileInput.files[0];
            // 获取图片路径
            var url = getFileUrl(file);
            // 显示图片
            $(fileInput).siblings('.upload-img').attr('src', url).show();
            // 上传图片
            singleFileUpload(file, function(data){
                imgList[type] = data.uploadId
            })
        }
        
        function submitCard(){
            var msg = {
                cardId: '请上传身份证',
                studentId: '请上传学生证',
                studyId: '请上传毕业证'
            }
            // 验证数据不为空
            for(let k in imgList){
                if(validEmpty(imgList[k], msg[k])) return false;
            }
            
            // 数据写入表单
            for(let k in imgList){
                $('[name=' + k + ']').val(imgList[k]);
            }
            $('#studentModule').hide();
            $('#main').show();
            return false;
        }
    </script>
</body>
</html>